<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

abstract class Image_Driver {

		protected $image;

		protected $tmp_image;

		protected $errors = array();

	
	public function execute($actions)
	{
		foreach ($actions as $func => $args)
		{
			if ( ! $this->$func($args))
				return FALSE;
		}

		return TRUE;
	}

	
	protected function sanitize_geometry( & $geometry)
	{
		list($width, $height) = $this->properties();

				$reporting = error_reporting(0);

				$geometry['width']  = min($geometry['width'], $width);
		$geometry['height'] = min($geometry['height'], $height);

				if ($geometry['top'] === 'center')
		{
			$geometry['top'] = floor(($height / 2) - ($geometry['height'] / 2));
		}
		elseif ($geometry['top'] === 'top')
		{
			$geometry['top'] = 0;
		}
		elseif ($geometry['top'] === 'bottom')
		{
			$geometry['top'] = $height - $geometry['height'];
		}

				if ($geometry['left'] === 'center')
		{
			$geometry['left'] = floor(($width / 2) - ($geometry['width'] / 2));
		}
		elseif ($geometry['left'] === 'left')
		{
			$geometry['left'] = 0;
		}
		elseif ($geometry['left'] === 'right')
		{
			$geometry['left'] = $width - $geometry['height'];
		}

				error_reporting($reporting);
	}

	
	abstract protected function properties();

	
	abstract public function process($image, $actions, $dir, $file);

    
	abstract function flip($direction);

	
	abstract function crop($properties);

	
	abstract public function resize($properties);

    
	abstract public function rotate($amount);

	
	abstract public function sharpen($amount);

} 